﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Windows.Forms;
using RCREEE.Library.Entities;
using System.Data;

namespace RCREEE.Web
{
    public partial class LookUps : System.Web.UI.Page
    {
        int[] LanguageCode = { 1033, 1025, 1036 };
        List<Lookups> lookups = new List<Lookups>();
        Lookups lookupsclass = new Lookups();
        ListItem li1 = new ListItem();

        protected void Page_Load(object sender, EventArgs e)
        {//Add Session in load page
    
            AddNew.Visible = true;

            //if (Session["LanguagCode"] != null)
            //    Session.Add("LanguagCode", "1033");
           
        }


        #region DetailsVeiw
        public void RefreshOrderDetailsveiw( string DD1,string DD2)
        {
            if (DD1 != "" && DD2 != "")
            {
                DataTable x = lookupsclass.GetItemsLookUps(Convert.ToInt32(DD1), Convert.ToInt32(DD2));
              
                DetailsView.DataSource = x;

                DetailsView.DataBind();
            }

        }
        protected void DetailsView_DataBound(object sender, EventArgs e)
        {

            // Check formViewMode if in Edit
            if (DetailsView.CurrentMode == FormViewMode.Edit || DetailsView.CurrentMode == FormViewMode.Insert)
            {
                //Bind value in hiddenfeild to ddcategory && ddItemEdit
                try
                {

                    li1.Text = "";
                    li1.Value = Convert.ToString(0) ;
                    List<TinyItem> x = lookupsclass.GetCategories();

                    ((DropDownList)DetailsView.FindControl("ddCategory")).DataSource = x;
                    ((DropDownList)DetailsView.FindControl("ddCategory")).DataTextField = "Name";
                    ((DropDownList)DetailsView.FindControl("ddCategory")).DataValueField = "ID";
                    ((DropDownList)DetailsView.FindControl("ddCategory")).DataBind();
                    ((DropDownList)DetailsView.FindControl("ddCategory")).Items.Insert(0, li1);
                    ((DropDownList)DetailsView.FindControl("ddCategory")).SelectedValue = CategoryLB.SelectedValue;
                    

                    ////((DropDownList)DetailsView.FindControl("ddCategoryEdit")).SelectedValue = ((HiddenField)DetailsView.FindControl("Category")).Value;
                    ////((DropDownList)(DetailsView.FindControl("ddItemEdit"))).SelectedValue = ((HiddenField)DetailsView.FindControl("Item")).Value;
                    ////// to refresh ddItemEdit 
                    ////((DropDownList)(DetailsView.FindControl("ddItemEdit"))).DataBind();

                 

                    ////Check if selectedvalue of ddcategory if fields (8)
                    //if (((DropDownList)(DetailsView.FindControl("ddCategory"))).SelectedValue == "8")
                    //{
                    //    //Convert Text from parent to Entity ...
                    //    ((LinkButton)DetailsView.FindControl("Parent")).Text = "Entity";
                    //    // convert Combobox of category from field to Entity
                    //    ((DropDownList)(DetailsView.FindControl("ddCategory"))).SelectedValue = "1";
                    //    //dim ddCategoryEdit
                    //    ((DropDownList)(DetailsView.FindControl("ddCategory"))).Enabled = false;
                    //    //dim ddItemEdit
                    //    ((DropDownList)(DetailsView.FindControl("ddItemEdit"))).Enabled = false;
                    //}

                
                }
                catch (Exception)
                {

                }
               
            }
            if (DetailsView.CurrentMode == FormViewMode.ReadOnly || DetailsView.CurrentMode == FormViewMode.Insert || DetailsView.CurrentMode == FormViewMode.Edit)
            {
                AddnewG.Visible = false;
            }else
                AddnewG.Visible = true;
        }

        protected void DetailsView_ItemCommand(object sender, FormViewCommandEventArgs e)
        {
            //if (DetailsView.CurrentMode == FormViewMode.Edit)
            //{
            //    // to fill hidden to bind and update
            //    ((HiddenField)DetailsView.FindControl("CurrentCategoryId")).Value = ((DropDownList)DetailsView.FindControl("ddCategory")).SelectedValue;
            //    ((HiddenField)DetailsView.FindControl("CurrentItemId")).Value = ((DropDownList)DetailsView.FindControl("ddItemEdit")).SelectedValue;

            //    //if (((DropDownList)DetailsView.FindControl("ddParent")).SelectedIndex != -1)
            //    //    ((HiddenField)DetailsView.FindControl("CurrentParentId")).Value = ((DropDownList)DetailsView.FindControl("ddParent")).SelectedValue;
            //    //else
            //    //    ((HiddenField)DetailsView.FindControl("CurrentParentId")).Value = CurrentPageParentId.Value;
            //}

            ////check on formveiwMode is Readonly
            //if (DetailsView.CurrentMode == FormViewMode.ReadOnly)
            //{
            //    try
            //    {// equal hiddenfield in form "webpage" with hiddenfield"parentItemId" ..when go to edit select actual value and sent to its function

            //        CurrentPageParentId.Value = ((HiddenField)DetailsView.FindControl("ParentId")).Value;

            //    }
            //    catch (Exception)
            //    {

            //    }
            //}
           
        }

        protected void DetailsView_ItemInserting(object sender, FormViewInsertEventArgs e)
        {
            for (int i = 0; i < 3; i++)
            {
                lookups.Add(new Lookups());
                if (((DropDownList)DetailsView.FindControl("ddCategory")).SelectedValue != "0")
                { lookups[i].CategoryId = Convert.ToInt32(((DropDownList)DetailsView.FindControl("ddCategory")).SelectedValue); }
                //if (((DropDownList)DetailsView.FindControl("ddCategory")).SelectedValue != "9")
                //{
                //    lookups[i].ParentItemId = Convert.ToInt32(((DropDownList)DetailsView.FindControl("ddParentInsert")).SelectedValue);
                //}
                //else lookups[i].ParentItemId = 0;
                lookups[i].LanguageCode = LanguageCode[i];
                lookups[i].Name = ((System.Web.UI.WebControls.TextBox)DetailsView.FindControl("Name" + i)).Text;
                lookups[i].Description = ((System.Web.UI.WebControls.TextBox)DetailsView.FindControl("Description" + i)).Text;

            }
           int index = lookupsclass.InsertItemProjectGroups(lookups);
           DetailsView.ChangeMode(FormViewMode.ReadOnly);
            RefreshOrderDetailsveiw(Convert.ToString(lookups[0].CategoryId) ,index.ToString());
            CategoryLB.SelectedValue = Convert.ToString(lookups[0].CategoryId);

            ItemLB.DataBind();
        }

        protected void DetailsView_ItemDeleting(object sender, FormViewDeleteEventArgs e)
        {
            lookupsclass.DeleteItemProjectGroup(Convert.ToInt32(((HiddenField)DetailsView.FindControl("ItemId")).Value));
            DetailsView.DataBind();
            ItemLB.SelectedIndex = -1;
            ItemLB.DataBind();
            AddnewG.Visible = true;
        }

        protected void DetailsView_ItemUpdating(object sender, FormViewUpdateEventArgs e)
        {


            for (int i = 0; i < 3; i++)
            {
                lookups.Add(new Lookups());
                lookups[i].CategoryId = Convert.ToInt32(((DropDownList)DetailsView.FindControl("ddCategory")).SelectedValue);
                lookups[i].ItemId = Convert.ToInt32(ItemLB.SelectedValue);
            // lookups[i].ParentItemId=
                lookups[i].LanguageCode = LanguageCode[i];
                lookups[i].Name = ((System.Web.UI.WebControls.TextBox)DetailsView.FindControl("Name" + i)).Text;
                lookups[i].Description = ((System.Web.UI.WebControls.TextBox)DetailsView.FindControl("Description" + i)).Text;

            }
            lookupsclass.UpdateItemLookUps(lookups);
            e.Cancel = true;
            DetailsView.ChangeMode(FormViewMode.ReadOnly);
          
            RefreshOrderDetailsveiw(Convert.ToString(lookups[0].CategoryId), Convert.ToString(lookups[0].ItemId));
            DetailsView.DataBind();
        }

        protected void DetailsView_ItemUpdated(object sender, FormViewUpdatedEventArgs e)
        {
            e.KeepInEditMode = false;
            DetailsView.ChangeMode(FormViewMode.ReadOnly);
            ItemLB.DataBind();
        }

        protected void DetailsView_ModeChanging(object sender, FormViewModeEventArgs e)
        {
            DetailsView.ChangeMode(e.NewMode);

            if (e.NewMode != FormViewMode.Insert)
            {
                RefreshOrderDetailsveiw(CategoryLB.SelectedValue, ItemLB.SelectedValue);
            }
        }

        protected void DetailsView_ItemDeleted(object sender, FormViewDeletedEventArgs e)
        {
            AddnewG.Visible = true;
        }

        #endregion

        #region FormVeiw2

        protected void FormView2_ItemDeleting(object sender, FormViewDeleteEventArgs e)
        {
            lookupsclass.DeleteItemProjectGroup(Convert.ToInt32(ProjectGroupslb.SelectedValue));
            FormView2.DataBind();
            ProjectGroupslb.DataBind();
        }
        protected void FormView2_ItemUpdating(object sender, FormViewUpdateEventArgs e)
        {
            for (int i = 0; i < 3; i++)
            {
                lookups.Add(new Lookups());

                lookups[i].ItemId = Convert.ToInt32(ProjectGroupslb.SelectedValue);
                lookups[i].CategoryId = 9;
                lookups[i].LanguageCode = LanguageCode[i];
                lookups[i].Name = ((System.Web.UI.WebControls.TextBox)FormView2.FindControl("Name" + i)).Text;
                lookups[i].Description = ((System.Web.UI.WebControls.TextBox)FormView2.FindControl("Description" + i)).Text;

            }
            lookupsclass.UpdateprojectGroups(lookups);
           FormView2.ChangeMode(FormViewMode.ReadOnly);

           RefreshOrderformveiw2(Convert.ToInt32(ProjectGroupslb.SelectedValue));
        }
        protected void FormView2_ItemInserting(object sender, FormViewInsertEventArgs e)
        {

            for (int i = 0; i < 3; i++)
            {
                lookups.Add(new Lookups());
                lookups[i].CategoryId = 9;
                lookups[i].ParentItemId = 0;
                lookups[i].LanguageCode = LanguageCode[i];
                lookups[i].Name = ((System.Web.UI.WebControls.TextBox)FormView2.FindControl("Name" + i)).Text;
                lookups[i].Description = ((System.Web.UI.WebControls.TextBox)FormView2.FindControl("Description" + i)).Text;

            }
            int index=lookupsclass.InsertItemProjectGroups(lookups);
            FormView2.ChangeMode(FormViewMode.ReadOnly);
            RefreshOrderformveiw2(index);
            ProjectGroupslb.DataBind();
        }
        protected void FormView2_ModeChanging(object sender, FormViewModeEventArgs e)
        {
            FormView2.ChangeMode(e.NewMode);

            if (e.NewMode != FormViewMode.Insert)
            {
                if (ProjectGroupslb.SelectedValue != "")
                {
                    RefreshOrderformveiw2(Convert.ToInt32(ProjectGroupslb.SelectedValue));
                }else
                    RefreshOrderformveiw2(0);
            }
        }
        public void RefreshOrderformveiw2(int DD1)
        {
            if (DD1 != null && DD1!=0 )
            {
                DataTable x = lookupsclass.GetItemProjectGroups(DD1);

                FormView2.DataSource = x;

                FormView2.DataBind();
            }

        }
        protected void FormView2_ItemDeleted(object sender, FormViewDeletedEventArgs e)
        {
            ProjectGroupslb.DataBind();
        }
        #endregion

        #region Formveiw3

        protected void FormView3_ItemDeleting(object sender, FormViewDeleteEventArgs e)
        {
            lookupsclass.DeleteItemProjectGroup(Convert.ToInt32(((HiddenField)FormView3.FindControl("ItemId")).Value));
            FormView3.DataBind();
            ProjectTypes.DataBind();
        }

        protected void FormView3_DataBound(object sender, EventArgs e)
        {
            if (FormView3.CurrentMode == FormViewMode.Insert)
            {
                ((DropDownList)FormView3.FindControl("ProjectGroups")).SelectedValue = ProjectGroupslb.SelectedValue;
            }

            //if (FormView3.CurrentMode == FormViewMode.ReadOnly || FormView3.CurrentMode == FormViewMode.Insert || FormView3.CurrentMode == FormViewMode.Edit)
            //{
            //    NewType.Visible = false;
            //}
            //else
            //    NewType.Visible = true;
            if(FormView3.DataItemCount==0)
            {
                NewType.Visible = true;
            }
            else
                NewType.Visible =false;



        }

        protected void FormView3_ItemUpdating(object sender, FormViewUpdateEventArgs e)
        {
            for (int i = 0; i < 3; i++)
            {
                lookups.Add(new Lookups());
                lookups[i].ItemId = Convert.ToInt32(ProjectTypes.SelectedValue);
                lookups[i].CategoryId = 2;
                lookups[i].ParentItemId = Convert.ToInt32(((DropDownList)FormView3.FindControl("ProjectGroups")).SelectedValue);
                lookups[i].LanguageCode = LanguageCode[i];
                lookups[i].Name = ((System.Web.UI.WebControls.TextBox)FormView3.FindControl("Name" + i)).Text;
                lookups[i].Description = ((System.Web.UI.WebControls.TextBox)FormView3.FindControl("Description" + i)).Text;

            }
            lookupsclass.UpdateItemLookUps(lookups);
             FormView3.ChangeMode(FormViewMode.ReadOnly);

             RefreshOrderDetails(Convert.ToInt32(ProjectTypes.SelectedValue), Convert.ToInt32(Session["LanguageCode"]), FormView3);
 
        }
        protected void FormView3_ItemInserting(object sender, FormViewInsertEventArgs e)
        {

            for (int i = 0; i < 3; i++)
            {
                lookups.Add(new Lookups());
                lookups[i].CategoryId = 2;
                lookups[i].ParentItemId = Convert.ToInt32(((DropDownList)FormView3.FindControl("ProjectGroups")).SelectedValue);
                lookups[i].LanguageCode = LanguageCode[i];
                lookups[i].Name = ((System.Web.UI.WebControls.TextBox)FormView3.FindControl("Name" + i)).Text;
                lookups[i].Description = ((System.Web.UI.WebControls.TextBox)FormView3.FindControl("Description" + i)).Text;

            }
           int index= lookupsclass.InsertItemProjectGroups(lookups);
           FormView3.ChangeMode(FormViewMode.ReadOnly);

           RefreshOrderDetails(index, Convert.ToInt32(Session["LanguageCode"]), FormView3);
           ProjectGroupslb.SelectedValue = lookups[0].ParentItemId.ToString();
          
           ProjectTypes.DataBind();
        }
        protected void FormView3_ModeChanging(object sender, FormViewModeEventArgs e)
        {
            FormView3.ChangeMode(e.NewMode);
           
            if (e.NewMode != FormViewMode.Insert)
            {
                if (ProjectTypes.SelectedValue != "")
                {
                    RefreshOrderDetails(Convert.ToInt32(ProjectTypes.SelectedValue), Convert.ToInt32(Session["LanguageCode"]), FormView3);

                }
                else
                    RefreshOrderDetails(0, Convert.ToInt32(Session["LanguageCode"]), FormView3);

            }
        }

      
        #endregion
      
        #region Buttons
         
        protected void AddNew_Click(object sender, EventArgs e)
        {
            FeildsFormveiw.Visible = true;
            FeildsFormveiw.ChangeMode(FormViewMode.Insert);
        }

        protected void Edit_Click(object sender, EventArgs e)
        {
            FormView3.Visible = true;
            FormView3.ChangeMode(FormViewMode.Edit);
        }
        protected void EditButton_Click(object sender, EventArgs e)
        {
           // RefreshOrderformveiw2();
            FormView2.Visible = true;
            FormView2.ChangeMode(FormViewMode.Edit);
        }
        protected void AddLookups_Click(object sender, EventArgs e)
        {
            DetailsView.Visible = true;
            DetailsView.ChangeMode(FormViewMode.Insert);
        }
        protected void NewButton0_Click(object sender, EventArgs e)
        {
            FormView2.Visible = true;
            FormView2.ChangeMode(FormViewMode.Insert);
        }
     
        protected void DeleteButton0_Click(object sender, EventArgs e)
        {
          
                lookupsclass.DeleteItemProjectGroup(Convert.ToInt32(ProjectGroupslb.SelectedValue));
                Response.Redirect("LookUps.aspx");
         
               
        }

        protected void DeleteButton_Click(object sender, EventArgs e)
        {
            if (ItemLB.SelectedIndex != -1)
            {
                lookupsclass.DeleteItemProjectGroup(Convert.ToInt32(ProjectTypes.SelectedValue));
                Response.Redirect("LookUps.aspx");
                
            }
           
               
        }

     
        #endregion
     
        #region FeildsFormveiw
        public void RefreshOrderDetails(int DD1,int Language,FormView form)
        {
            if (DD1 != 0 && Language != 0)
            {
                DataTable x = lookupsclass.GetProjectTypes(DD1,Language);

                form.DataSource = x;

                form.DataBind();
                
            }

        }
        protected void FeildsFormveiw_ItemUpdating(object sender, FormViewUpdateEventArgs e)
        {
            for (int i = 0; i < 3; i++)
            {
                lookups.Add(new Lookups());
                lookups[i].ItemId = Convert.ToInt32(LBFeilds.SelectedValue);
                lookups[i].CategoryId = 8;
                lookups[i].ParentItemId = Convert.ToInt32(((DropDownList)FeildsFormveiw.FindControl("Entities")).SelectedValue);
                lookups[i].LanguageCode = LanguageCode[i];
                lookups[i].Name = ((System.Web.UI.WebControls.TextBox)FeildsFormveiw.FindControl("Name" + i)).Text;
                lookups[i].Description = ((System.Web.UI.WebControls.TextBox)FeildsFormveiw.FindControl("Description" + i)).Text;

            }
            lookupsclass.UpdateItemLookUps(lookups);
            FeildsFormveiw.ChangeMode(FormViewMode.ReadOnly);

            RefreshOrderDetails(Convert.ToInt32(LBFeilds.SelectedValue), Convert.ToInt32(Session["LanguageCode"]), FeildsFormveiw);
            lbFeildsBind();
        }

        protected void FeildsFormveiw_DataBound(object sender, EventArgs e)
        {

            if (FeildsFormveiw.CurrentMode == FormViewMode.Edit || FeildsFormveiw.CurrentMode == FormViewMode.Insert)
            {
                li1.Text = "";
                li1.Value = "0";

                ((DropDownList)FeildsFormveiw.FindControl("Entities")).DataSource = lookupsclass.GetListItemsEntites(Convert.ToInt32(Session["LanguageCode"]));
                ((DropDownList)FeildsFormveiw.FindControl("Entities")).DataTextField = "Name";
                ((DropDownList)FeildsFormveiw.FindControl("Entities")).DataValueField = "ID";
                ((DropDownList)FeildsFormveiw.FindControl("Entities")).DataBind();
                ((DropDownList)FeildsFormveiw.FindControl("Entities")).Items.Insert(0, li1);
                ((DropDownList)FeildsFormveiw.FindControl("Entities")).SelectedValue = LBEntities.SelectedValue;
                AddNew.Visible = false;
            }
            if (FeildsFormveiw.CurrentMode == FormViewMode.ReadOnly)
            {
                AddNew.Visible = false;

            }

            if (FeildsFormveiw.CurrentMode == FormViewMode.Insert)
            {
                ((DropDownList)FeildsFormveiw.FindControl("Entities")).SelectedValue = LBEntities.SelectedValue;
            }

            if (FeildsFormveiw.CurrentMode == FormViewMode.ReadOnly || FeildsFormveiw.CurrentMode == FormViewMode.Insert || FeildsFormveiw.CurrentMode == FormViewMode.Edit)
            {
                AddNew.Visible = false;
            }
            else
                AddNew.Visible = true;
        }

        protected void FeildsFormveiw_ItemInserting(object sender, FormViewInsertEventArgs e)
        {
            for (int i = 0; i < 3; i++)
            {
                lookups.Add(new Lookups());
                lookups[i].CategoryId = 8;
                lookups[i].ParentItemId = Convert.ToInt32(((DropDownList)FeildsFormveiw.FindControl("Entities")).SelectedValue);
                lookups[i].LanguageCode = LanguageCode[i];
                lookups[i].Name = ((System.Web.UI.WebControls.TextBox)FeildsFormveiw.FindControl("Name" + i)).Text;
                lookups[i].Description = ((System.Web.UI.WebControls.TextBox)FeildsFormveiw.FindControl("Description" + i)).Text;

            }
            LBEntities.SelectedValue =((DropDownList)FeildsFormveiw.FindControl("Entities")).SelectedValue;
         
            int index=lookupsclass.InsertItemProjectGroups(lookups);
            LBFeilds.DataBind();
            FeildsFormveiw.ChangeMode(FormViewMode.ReadOnly);

            RefreshOrderDetails(index, Convert.ToInt32(Session["LanguageCode"]), FeildsFormveiw);
            lbFeildsBind();
        }

        protected void FeildsFormveiw_ItemDeleting(object sender, FormViewDeleteEventArgs e)
        {
            lookupsclass.DeleteItemProjectGroup(Convert.ToInt32(((HiddenField)FeildsFormveiw.FindControl("ItemId")).Value));
            FeildsFormveiw.DataBind();
            lbFeildsBind();
        }

        protected void FeildsFormveiw_ModeChanging(object sender, FormViewModeEventArgs e)
        {
            FeildsFormveiw.ChangeMode(e.NewMode);

            if (e.NewMode != FormViewMode.Insert)
            {
                if (LBFeilds.SelectedValue != "")
                {
                    RefreshOrderDetails(Convert.ToInt32(LBFeilds.SelectedValue), Convert.ToInt32(Session["LanguageCode"]), FeildsFormveiw);
                  
                }
                else
                {
                    RefreshOrderDetails(0, Convert.ToInt32(Session["LanguageCode"]), FeildsFormveiw);
               
                }
  
            }
        }

        protected void LBFeilds_SelectedIndexChanged(object sender, EventArgs e)
        {

            RefreshOrderDetails(Convert.ToInt32(LBFeilds.SelectedValue), Convert.ToInt32(Session["LanguageCode"]), FeildsFormveiw);

        
            FeildsFormveiw.Visible = true;
            FeildsFormveiw.ChangeMode(FormViewMode.ReadOnly);
        }


        #endregion

        protected void ProjectGroupslb_SelectedIndexChanged(object sender, EventArgs e)
        {
            ProjectTypes.Visible = true;
            
            NewType.Visible = true;
            NewButton0.Visible = true;

            RefreshOrderformveiw2(Convert.ToInt32(ProjectGroupslb.SelectedValue));
            FormView2.Visible = true;
            FormView2.ChangeMode(FormViewMode.ReadOnly);

            FormView3.DataBind();
        }

        protected void ProjectTypes_SelectedIndexChanged(object sender, EventArgs e)
        {
            RefreshOrderDetails(Convert.ToInt32(ProjectTypes.SelectedValue), Convert.ToInt32(Session["LanguageCode"]), FormView3);
        
            FormView3.Visible = true;
            FormView3.ChangeMode(FormViewMode.ReadOnly);
        }

        protected void ItemLB_SelectedIndexChanged(object sender, EventArgs e)
        {
            RefreshOrderDetailsveiw(CategoryLB.SelectedValue,ItemLB.SelectedValue);
            DetailsView.Visible = true;
            DetailsView.ChangeMode(FormViewMode.ReadOnly);
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            DetailsView.Visible = true;
            DetailsView.ChangeMode(FormViewMode.Insert);
        }

        protected void FormView3_ItemDeleted(object sender, FormViewDeletedEventArgs e)
        {
            ProjectTypes.DataBind();
        }

     
        public void lbFeildsBind()
        {
            List<TinyItem> dt = lookupsclass.GetItemFeilds(Convert.ToInt32(LBEntities.SelectedValue), Convert.ToInt32(Session["LanguageCode"]));
            if (dt.Count == 0)
            {
                TinyItem x = new TinyItem();
                x.ID = 0;
                x.Name = "No Data Row";
                dt.Add(x);
                LBFeilds.DataSource = dt;
                LBFeilds.DataTextField = "Name";
                LBFeilds.DataValueField = "ID";
                LBFeilds.DataBind();


            }

            else
            {
                LBFeilds.DataSource = dt;
                LBFeilds.DataTextField = "Name";
                LBFeilds.DataValueField = "ID";
                LBFeilds.DataBind();


            }
        }
        protected void LBEntities_SelectedIndexChanged(object sender, EventArgs e)
        {
            lbFeildsBind();
        }

        protected void FormView2_DataBound(object sender, EventArgs e)
        {
            //if (FormView2.CurrentMode == FormViewMode.ReadOnly || FormView2.CurrentMode == FormViewMode.Insert || FormView2.CurrentMode == FormViewMode.Edit)
            //{
            //    NewButton0.Visible = false;
            //}
            //else
            //    NewButton0.Visible = true;

            if (FormView2.DataItemCount == 0)
            {
                NewButton0.Visible = true;
            }
            else
                NewButton0.Visible = false;
        }

        protected void InsertCancelButton_Click(object sender, EventArgs e)
        {
            NewType.Visible = true;
            
        }

        protected void UpdateCancelButton_Click(object sender, EventArgs e)
        {
            AddnewG.Visible = true;
        }

        protected void UpdateCancelButton_Click1(object sender, EventArgs e)
        {
            AddNew.Visible = true;
        }

        protected void InsertCancelButton_Click1(object sender, EventArgs e)
        {
            NewButton0.Visible = true;
        }

        protected void NewType_Click(object sender, EventArgs e)
        {
            FormView3.Visible = true;
            FormView3.ChangeMode(FormViewMode.Insert);
        }

 


      

      
      
       

       

     

      

       

    
      
      
       
     
       

      
    
     
     
      

       
       

 
     
    }
}